import java.math.BigDecimal;
import java.util.Scanner;

public class Test1 {
    /**
     *
     * @param args
     */
    public static void main(String[] args) {
        Fruit fruit;
        System.out.println("本店出售苹果和草莓，输入a：苹果，b：草莓，c：芒果， 其他按键：退出");
        System.out.println("输入格式为：水果类型 水果公斤数");
        System.out.println("请输入：");
        Scanner scanner = new Scanner(System.in);
        Cart cart = new Cart();
        while (scanner.hasNext()) {
            String str = scanner.nextLine();
            if(!str.startsWith("a") && !str.startsWith("b") && !str.startsWith("c")) {
                break;
            }
            String[] arr = str.split(" ");
            int kilo = Integer.parseInt(arr[1]);
            if("a".equals(arr[0])) {
                fruit = new Apple();
            } else if("b".equals(arr[0])) {
                fruit = new Strawberry();
            } else if("c".equals(arr[0])) {
                fruit = new Mango();
            } else {
                break;
            }
            cart.addFruit(fruit, kilo);

        }
        BigDecimal totalPrice = cart.getTotalPrice();
        System.out.println(totalPrice);
        cart = new Cart();
        System.out.println("本店开展促销活动，草莓限时打8折");
        System.out.println("输入a：苹果，b：草莓，c：芒果， 其他按键：退出");
        System.out.println("输入格式为：水果类型 水果公斤数");
        System.out.println("请输入：");
        while (scanner.hasNext()) {
            String str = scanner.nextLine();
            if(!str.startsWith("a") && !str.startsWith("b") && !str.startsWith("c")) {
                break;
            }
            String[] arr = str.split(" ");
            int kilo = Integer.parseInt(arr[1]);
            if("a".equals(arr[0])) {
                fruit = new Apple();
            } else if("b".equals(arr[0])) {
                fruit = new Strawberry();
                PromotionStrategy promotionStrategy = new PercentPromotionStrategy(fruit, new BigDecimal(0.8));
                fruit.setPrice(promotionStrategy.computeDiscountPrice());
            } else if("c".equals(arr[0])) {
                fruit = new Mango();
            } else {
                break;
            }
            cart.addFruit(fruit, kilo);

        }
        totalPrice = cart.getTotalPrice();
        System.out.println(totalPrice);

        System.out.println("本店开展促销活动，购买满100减10元");
        System.out.println("输入a：苹果，b：草莓，c：芒果， 其他按键：退出");
        System.out.println("输入格式为：水果类型 水果公斤数");
        System.out.println("请输入：");
        cart = new Cart();
        while (scanner.hasNext()) {
            String str = scanner.nextLine();
            if(!str.startsWith("a") && !str.startsWith("b") && !str.startsWith("c")) {
                break;
            }
            String[] arr = str.split(" ");
            int kilo = Integer.parseInt(arr[1]);
            if("a".equals(arr[0])) {
                fruit = new Apple();
            } else if("b".equals(arr[0])) {
                fruit = new Strawberry();
            } else if("c".equals(arr[0])) {
                fruit = new Mango();
            } else {
                break;
            }
            cart.addFruit(fruit, kilo);

        }
        totalPrice = cart.getTotalPrice();
        PromotionStrategy promotionStrategy = new SpendSavePromotionStrategy(totalPrice, 100, 10);
        System.out.println(promotionStrategy.computeDiscountPrice());

    }
}
